package com.cbgolf.oa.model;

import android.support.v4.util.ArrayMap;
import android.util.Log;
import com.cbgolf.oa.base.BaseModel;
import com.cbgolf.oa.contract.IOrderContract.IOrderFragModel;
import com.cbgolf.oa.event.EventOrder;
import com.cbgolf.oa.manager.DataManager;
import com.cbgolf.oa.manager.OrderManager;
import com.cbgolf.oa.net.NetCallBack;
import com.cbgolf.oa.net.Web;
import com.cbgolf.oa.net.WebAPI;
import com.cbgolf.oa.viewbean.OrderBean;
import java.util.Map;
import org.greenrobot.eventbus.EventBus;

/**
 * @author lq
 * @date 2018/4/12
 */

public class OrderFragModelImp extends BaseModel implements IOrderFragModel {

    @Override
    public void getData(String orderState, String orderType, int type) {
        String url = WebAPI.order_all_list_get;
        Map<String, String> map = new ArrayMap<>();
        map.put("orderState", orderState);
        map.put("orderClassification", orderType);
        Log.e("orderState--------", OrderManager.getOrderState(orderState));
        Log.e("orderType--------", OrderManager.getOrderType(orderType));
        map.put("pageSize", pageSize + "");
        map.put("currentPage", String.valueOf((type == LOADMORE) ? (++page) : 0));
        Web.getOK(url, map, new NetCallBack(response -> {
            EventBus.getDefault().post(new EventOrder.Builder()
                    .setListOrder(getList(response, OrderBean.class))
                    .setRequestType(type)
                    .setTarget(DataManager.ORDER_LIST)
                    .setOrderState(orderState)
                    .setOrderType(orderType)
                    .setError(errorMsg, errorCode)
                    .build());
        }));
    }
}
